<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/9/8 0008
 * Time: 09:46
 */

namespace app\api\controller\v1\cleaner;


use app\api\controller\v1\Cleaner;
use app\currency\service\CitiesService;
use think\Db;

class BindOrder extends Cleaner
{
    public function read($id)
    {
        $cities = Db::name('Cities')->where('id',$id)->find();
        empty($cities) && $this->error('error');
        $cities['address_txt'] = CitiesService::getAddressText($id,'string');
        $where = [['cities_id','eq',$id],['status','egt','0']];
        $list = $this->_query('CleanOrder')->where($where)->page(true,false,false,10);
        $mids = array_unique(array_column($list['list'],'mid'));
        $member_list = Db::name('Member')->whereIn('id',$mids)->select();
        foreach ($list['list'] as &$item) {
            $item['member'] = [];
            foreach ($member_list as $member) if($item['mid'] == $member['id']) {
                $item['member'] = $member;
            }
        }
        $list['cities'] = $cities;
        $this->success('success',$list);
    }
}